package cm.wc;

import java.sql.*;

/**
 * @ClassName:jdbcincre
 * @Author: 鹿建文
 * @Date: 2022/3/30  - 9:47
 * @Describe:
 */
public class jdbcincre {
    private static String url = "jdbc:mysql://localhost:3306/db_test?useSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF8&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true";
    private static String user = "root";
    private static String password = "root";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //创建conn对象，获取连接
        Connection conn = DriverManager.getConnection(url, user, password);
        //获取statement队形
        Statement stmt = conn.createStatement();
        //执行sql，处理结果
        String sql = "insert into tbtest (name ,author,birth,price)values('azs','sa','1998-08-16',88.8)";
        int i = stmt.executeUpdate(sql);
        System.out.println(i);

            try {
                if (stmt!=null){
                    stmt.close();
                }

            } catch (SQLException e) {
                e.printStackTrace();
            } finally {

                try {
                    if (conn!=null){
                        conn.close();
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }

